﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace ClientRegister
{
    public partial class OldStudentRegisClassForm : Form
    {
        public string id{set; get;}
        public string name { set; get; }
        public string birthday { set; get; }
        public string gender { set; get; }
        public string career { set; get; }
        public string email { set; get; }
        public string phone { set; get; }
        public string address { set; get; }

        SynchronizeData sync = new SynchronizeData();

        public OldStudentRegisClassForm()
        {
            InitializeComponent();
        }

        private void OldStudentRegisClassForm_Load(object sender, EventArgs e)
        {
            ////Load du lieu tu server
            //sync.GetDataForInsertMethodWithID(sync.studentTb, sync.insertcol);
            //sync.GetDataForUpdateMethodWithID(sync.studentTb, sync.updatecol);

            ////Load du lieu lop hoc
            //sync.GetDataForInsertMethodWithNoneID(sync.ClassOfStu, sync.insertcol);
            //sync.GetDataForUpdateMethodWithNoneID(sync.ClassOfStu, sync.updatecol);

            //load thong tin hoc vien
            txtFullName.Text = name;
            txtBirthday.Text = birthday;
            txtGender.Text = gender;
            txtJob.Text = career;
            txtPhone.Text = phone;
            txtAddress.Text = address;
            txtEmail.Text = email;
            //load combobox khoa hoc
            CourseDataProvider course = new CourseDataProvider();
            DataSet dscourse = course.loadCourses();
            cbbCourse.DataSource = dscourse.Tables[0];
            cbbCourse.DisplayMember = "NameCourse";
            cbbCourse.ValueMember = "ID";
        }
    //load danh sach lop hoc khi chon mot khoa hoc
        private void cbbCourse_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cbbCourse.SelectedValue.ToString() == "System.Data.DataRowView") return;
            else
            {
                ClassDataProvider cls = new ClassDataProvider();
                DataSet dsclass = cls.loadClass(cbbCourse.SelectedValue.ToString());
                cbbClass.DataSource = dsclass.Tables[0];
                cbbClass.DisplayMember = "NameClass";
                cbbClass.ValueMember = "ID";
            }
        }
    //Load thong tin cua lop hoc
        private void cbbClass_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cbbClass.SelectedValue.ToString() == "System.Data.DataRowView") return;
            else
            {
                ClassDataProvider cls = new ClassDataProvider();
                SqlDataReader sdr = cls.ClassDetail(cbbClass.SelectedValue.ToString());
                if (sdr.Read())
                {
                    txtFee.Text = sdr.GetValue(0).ToString();
                    txtStudyDay.Text = sdr.GetValue(1).ToString();
                    txtTime.Text = sdr.GetValue(2).ToString();
                    txtStartDate.Text = (DateTime.Parse(sdr.GetValue(3).ToString())).ToShortDateString();
                    txtEndDate.Text = (DateTime.Parse(sdr.GetValue(4).ToString())).ToShortDateString();
                }
                sdr.Close();
            }
        }

        private void btnRegister_Click(object sender, EventArgs e)
        {

            ////Load du lieu tu server
            //sync.GetDataForInsertMethodWithID(sync.studentTb, sync.insertcol);
            //sync.GetDataForUpdateMethodWithID(sync.studentTb, sync.updatecol);

            ////Load du lieu lop hoc
            //sync.GetDataForInsertMethodWithNoneID(sync.ClassOfStu, sync.insertcol);
            //sync.GetDataForUpdateMethodWithNoneID(sync.ClassOfStu, sync.updatecol);

            StudentInClassDataProvider stdClass = new StudentInClassDataProvider();
            int result2 = stdClass.InsertStudentInClass(id, cbbClass.SelectedValue.ToString());

            ////=======Chuyen du Hoc vien lieu len webservice================================
            //string xml = stdClass.selectClassOfStu(id, cbbClass.SelectedValue.ToString());
            
            //sync.transfDataForInsertMethod(xml, sync.ClassOfStu);
            ////====================================================================

            if (result2 != 0)
                MessageBox.Show("Đăng ký thành công");
            else MessageBox.Show("Đăng ký không thành công");
        }

        private void btnPrint_Click(object sender, EventArgs e)
        {

        }

        private void button_Clear_Click(object sender, EventArgs e)
        {

        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
